/*
 * @LastEditors: tangdy tdy853839625@qq.com
 * @FilePath: /HumanGenerateVideo/src/service/api/auth.ts
 */
import { request } from '../request';

/** getToken 换token */
export function getToken(token: string) {
  return request<any>({
    url: '/user/getToken',
    method: 'post',
    data: {
      token: `Bearer ${token}`
    }
  });
}

/** 获取用户信息 */
export function getUserInfoApi() {
  return request<any>({
    url: '/user/getUserInfo',
    method: 'get'
  });
}

/** 获取用户信息 */
export function createUserApi(data: any) {
  return request<any>({
    url: '/user/create',
    method: 'post',
    data
  });
}

/**
 * Login
 *
 * @param userName User name
 * @param password Password
 */
export function fetchLogin(userName: string, password: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/login',
    method: 'post',
    data: {
      userName,
      password
    }
  });
}

/** Get user info */
export function fetchGetUserInfo() {
  return request<Api.Auth.UserInfo>({ url: '/auth/getUserInfo' });
}

/**
 * Refresh token
 *
 * @param refreshToken Refresh token
 */
export function fetchRefreshToken(refreshToken: string) {
  return request<Api.Auth.LoginToken>({
    url: '/auth/refreshToken',
    method: 'post',
    data: {
      refreshToken
    }
  });
}

/**
 * return custom backend error
 *
 * @param code error code
 * @param msg error message
 */
export function fetchCustomBackendError(code: string, msg: string) {
  return request({ url: '/auth/error', params: { code, msg } });
}
